package cn.kgc.ssm.web.response;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;

/**
 * @author 课工场
 * @date 2024/7/29
 * @description 统一响应结果
 */
@Data
@JsonInclude(JsonInclude.Include.NON_NULL)   //   转换成 json格式数据时 剔除为null的属性
public class ResponseResult {

    // 状态码   layUi中 成功状态码为 0
    private Integer code;

    // 提示信息
    private String msg;

    // 页面数据
    private Object data;

    // 分页的数据总条数
    private Long count;

    //  成功
    public static ResponseResult success() {
        ResponseResult responseResult = new ResponseResult();
        responseResult.setCode(0);
        responseResult.setMsg("操作成功");
        return responseResult;
    }
    // 失败
    public static ResponseResult fail() {
        ResponseResult responseResult = new ResponseResult();
        responseResult.setCode(110);
        responseResult.setMsg("操作失败");
        return responseResult;
    }
    // 异常
    public static ResponseResult error() {
        ResponseResult responseResult = new ResponseResult();
        responseResult.setCode(500);
        responseResult.setMsg("系统繁忙,请稍后再试!!!");
        return responseResult;
    }


    // 改变提示信息
    public ResponseResult  message(String msg){
        this.msg = msg;
        return this;
    }

    // 设置数据总条数
    public ResponseResult  count(Long count){
        this.count = count;
        return this;
    }

    // 设置页面数据
    public ResponseResult  data(Object data){
        this.data = data;
        return this;
    }


    // 设置数据总条数
    public ResponseResult  code(Integer code){
        this.code = code;
        return this;
    }
}
